
import java.awt.image.ComponentSampleModel;
import javax.swing.JOptionPane;
//import java.awt.*;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ISS_SIMD_FIR_form.java
 *
 * Created on 01-May-2009, 19:49:59
 */

/**
 *
 * @author kpatel
 */
public class ISS_SIMD_FIR_form extends javax.swing.JFrame {

    /** Creates new form ISS_SIMD_FIR_form */
    public ISS_SIMD_FIR_form() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        label_rows = new javax.swing.JLabel();
        textfield_rows = new javax.swing.JTextField();
        button_OK = new javax.swing.JButton();
        button_cancel = new javax.swing.JButton();
        button_clearall = new javax.swing.JButton();
        textfield_columns = new javax.swing.JTextField();
        label_columns = new javax.swing.JLabel();
        label_taps = new javax.swing.JLabel();
        label_samples = new javax.swing.JLabel();
        label_channels = new javax.swing.JLabel();
        textfield_taps = new javax.swing.JTextField();
        textfield_samples = new javax.swing.JTextField();
        textfield_channels = new javax.swing.JTextField();
        label_RAM = new javax.swing.JLabel();
        textfield_RAM = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        label_rows.setText("Enter no of rows for CFU array");

        button_OK.setText("OK");
        button_OK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button_OKActionPerformed(evt);
            }
        });

        button_cancel.setText("Cancel");
        button_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button_cancelActionPerformed(evt);
            }
        });

        button_clearall.setText("Clear all");
        button_clearall.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button_clearallActionPerformed(evt);
            }
        });

        label_columns.setText("Enter no of columns for CFU array");

        label_taps.setText("Enter no of taps in  FIR filter");

        label_samples.setText("Enter no of samples to process");

        label_channels.setText("Enter no of channels you want process in parallel");

        label_RAM.setText("Enter the size of RAM");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(label_rows)
                            .addComponent(label_columns))
                        .addGap(10, 10, 10))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(label_samples)
                            .addComponent(label_taps)
                            .addComponent(label_channels)
                            .addComponent(label_RAM))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(textfield_columns)
                    .addComponent(textfield_rows, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE)
                    .addComponent(textfield_taps)
                    .addComponent(textfield_samples)
                    .addComponent(textfield_channels)
                    .addComponent(textfield_RAM))
                .addContainerGap(146, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(111, Short.MAX_VALUE)
                .addComponent(button_OK)
                .addGap(29, 29, 29)
                .addComponent(button_cancel)
                .addGap(18, 18, 18)
                .addComponent(button_clearall)
                .addGap(104, 104, 104))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textfield_rows, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label_rows))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(textfield_columns, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textfield_taps, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label_taps))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textfield_samples, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label_samples))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(textfield_channels, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(textfield_RAM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(label_RAM)))
                            .addComponent(label_channels)))
                    .addComponent(label_columns))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(button_OK)
                    .addComponent(button_clearall)
                    .addComponent(button_cancel))
                .addGap(37, 37, 37))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void button_clearallActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_clearallActionPerformed
        // This function clear all the fields of the form.
        //textfield_rows.setText("");
        initComponents();
       
}//GEN-LAST:event_button_clearallActionPerformed

    private void button_OKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_OKActionPerformed
        /* This code performs the basic calculation before mapping application
         to the array
         */
        JOptionPane.showMessageDialog(null,"Jai Sairam..The program started 2...!");
        ISS_SIMD_FIR_16points_256samples.no_cfu_row_int = Integer.parseInt(textfield_rows.getText());
        ISS_SIMD_FIR_16points_256samples.no_cfu_column_int = Integer.parseInt(textfield_columns.getText());
        ISS_SIMD_FIR_16points_256samples.no_taps_int = Integer.parseInt(textfield_taps.getText());
        ISS_SIMD_FIR_16points_256samples.no_samples_int = Integer.parseInt(textfield_samples.getText());
        ISS_SIMD_FIR_16points_256samples.no_channels_int = Integer.parseInt(textfield_channels.getText());
        ISS_SIMD_FIR_16points_256samples.ram_size = Integer.parseInt(textfield_RAM.getText());


        ISS_SIMD_FIR_16points_256samples.total_cfu = ISS_SIMD_FIR_16points_256samples.no_cfu_column_int * ISS_SIMD_FIR_16points_256samples.no_cfu_row_int;
		ISS_SIMD_FIR_16points_256samples.no_cfu_per_channel =  ISS_SIMD_FIR_16points_256samples.total_cfu / ISS_SIMD_FIR_16points_256samples.no_channels_int;
		ISS_SIMD_FIR_16points_256samples.unused_cfu = ISS_SIMD_FIR_16points_256samples.total_cfu -
                (ISS_SIMD_FIR_16points_256samples.no_cfu_per_channel * ISS_SIMD_FIR_16points_256samples.no_channels_int);

        JOptionPane.showMessageDialog(null, "no_cfu_per_channel = " +
                ISS_SIMD_FIR_16points_256samples.no_cfu_per_channel+"\nchannels = "+
                ISS_SIMD_FIR_16points_256samples.no_channels_int+"\nunused = " + ISS_SIMD_FIR_16points_256samples.unused_cfu );


        ISS_SIMD_FIR_16points_256samples.Create_Cfu_Array();
        ISS_SIMD_FIR_16points_256samples.Create_RAM();
        

        ISS_SIMD_FIR_16points_256samples.Cfu_Array[0][1].update_register(1, 65);
       
		ISS_SIMD_FIR_16points_256samples.Cfu_Array[0][0].Cfu_initialize(1, 0, 1, 2, 3, 0);
		ISS_SIMD_FIR_16points_256samples.Cfu_Array[0][0].start_CFU();

    }//GEN-LAST:event_button_OKActionPerformed

    private void button_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_cancelActionPerformed
        // Exit the application if cancel button is pressed
        
        dispose();
    }//GEN-LAST:event_button_cancelActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ISS_SIMD_FIR_form().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton button_OK;
    private javax.swing.JButton button_cancel;
    private javax.swing.JButton button_clearall;
    private javax.swing.JLabel label_RAM;
    private javax.swing.JLabel label_channels;
    private javax.swing.JLabel label_columns;
    private javax.swing.JLabel label_rows;
    private javax.swing.JLabel label_samples;
    private javax.swing.JLabel label_taps;
    private javax.swing.JTextField textfield_RAM;
    private javax.swing.JTextField textfield_channels;
    private javax.swing.JTextField textfield_columns;
    private javax.swing.JTextField textfield_rows;
    private javax.swing.JTextField textfield_samples;
    private javax.swing.JTextField textfield_taps;
    // End of variables declaration//GEN-END:variables

}
